package com.csun.cmny.provider.service.impl;

import com.csun.cmny.base.dto.LoginAuthDto;
import com.csun.cmny.base.enums.ErrorCodeEnum;
import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.OmcRoomAssignmentMapper;
import com.csun.cmny.provider.exceptions.OmcBizException;
import com.csun.cmny.provider.model.RoomAndNursingVo;
import com.csun.cmny.provider.model.domain.OmcRoomAssignment;
import com.csun.cmny.provider.model.domain.OmcSchedul;
import com.csun.cmny.provider.model.domain.OmcSchedulMonth;
import com.csun.cmny.provider.model.domain.OmcShifts;
import com.csun.cmny.provider.model.dto.RoomAssignmentListDto;
import com.csun.cmny.provider.model.vo.OmcUserVo;
import com.csun.cmny.provider.model.vo.RpcRoleVo;
import com.csun.cmny.provider.pojo.Room;
import com.csun.cmny.provider.pojo.User;
import com.csun.cmny.provider.service.*;
import com.csun.cmny.provider.utils.MenuTimeUtil;
import com.csun.cmny.provider.utils.NursinglogUtil;
import com.csun.cmny.provider.vo.OmcSchedulMonthVo;
import com.csun.cmny.provider.vo.OmcUserDetailVo;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;

@Slf4j
@Service
@Transactional
public class OmcRoomAssignmentServiceImpl extends BaseService<OmcRoomAssignment> implements OmcRoomAssignmentService {

    @Resource
    private OmcRoomAssignmentMapper omcRoomAssignmentMapper;

    @Resource
    private OmcGroupService omcGroupService;

    @Resource
    private OmcScheduleService omcScheduleService;

    @Resource
    private UacRpcService uacRpcService;

    @Resource
    private OmcSchedulMonthService omcSchedulMonthServiceImpl;

    @Override
    public Integer save(RoomAssignmentListDto omcRoomAssignments, LoginAuthDto loginAuthDto) {

        //设置护工组id
        int nursingGroupId = getNursingGroupId(omcRoomAssignments.getNursingGroupId(),loginAuthDto);

        //校验用户是否是班长
        checkIsMonitor(loginAuthDto);

        //获取房间绑定List
        List<OmcRoomAssignment> omcRoomAssignmentList = omcRoomAssignments.getRoomAssList();

        //将操作人信息、date、shiftId放入List中每个对象
        for(OmcRoomAssignment item : omcRoomAssignmentList){
            item.setNursingGroupId(nursingGroupId);
            item.setUpdateInfo(loginAuthDto);
            item.setDate(omcRoomAssignments.getDate());
            if(omcRoomAssignments.getShiftsId() != null){
                item.setShiftsId(omcRoomAssignments.getShiftsId());
            }
        }

        //删除原来的list
        OmcRoomAssignment omcRoomAssignmentQuery = new OmcRoomAssignment();
        omcRoomAssignmentQuery.setShiftsId(omcRoomAssignments.getShiftsId());
        omcRoomAssignmentQuery.setDate(omcRoomAssignments.getDate());
        omcRoomAssignmentQuery.setNursingGroupId(nursingGroupId);
        int deleteRet = omcRoomAssignmentMapper.delete(omcRoomAssignmentQuery);

        //插入新的List
        int insertRet = batchSave(omcRoomAssignmentList);

        if(deleteRet >= 0 && insertRet >= 0){
            return 1;
        }else{
            return 0;
        }
    }

    //校验该用户是否是班长
    private void checkIsMonitor(LoginAuthDto loginAuthDto) {
        OmcUserDetailVo omcUserDetailVo = omcGroupService.queryUserDetail(loginAuthDto.getUserId(), loginAuthDto.getGroupId());
        if(!omcUserDetailVo.isMonitor()){
            throw new OmcBizException(ErrorCodeEnum.OMC10036008);
        }
    }

    @Override
    public List<Room> queryRoomAssList(OmcRoomAssignment omcRoomAssignment, LoginAuthDto loginAuthDto) {

        int nursingGroupId = getNursingGroupId(omcRoomAssignment.getNursingGroupId(),loginAuthDto);

        //创建查询对象
        OmcSchedul omcSchedulQuery = new OmcSchedul();
        //转换时间格式
        String week = MenuTimeUtil.getDays(omcRoomAssignment.getDate()).get(1) + MenuTimeUtil.getDays(omcRoomAssignment.getDate()).get(0);
        omcSchedulQuery.setWeek(Integer.parseInt(week));
        omcSchedulQuery.setNursingGroupId(nursingGroupId);
        omcSchedulQuery.setMonth(omcRoomAssignment.getMonth());
        //校验排班计划状态(周)
        List<OmcSchedul> schedulList = omcScheduleService.select(omcSchedulQuery);
        OmcSchedulMonth omcSchedulMonth = new OmcSchedulMonth();
        omcSchedulMonth.setMonth(omcRoomAssignment.getMonth());
        omcSchedulMonth.setNursingGroupId(omcRoomAssignment.getNursingGroupId());
        //校验排班计划状态(月)
        List<OmcSchedulMonth> select = omcSchedulMonthServiceImpl.select(omcSchedulMonth);
        if(schedulList == null || schedulList.size()<1 && (select == null || select.size() < 1)){
            throw new OmcBizException(ErrorCodeEnum.OMC10036001);
        }else{
            if(schedulList.size() > 0 && (schedulList.get(0).getStatus().equals(0) || schedulList.get(0).getStatus().equals(1))){
                throw new OmcBizException(ErrorCodeEnum.OMC10036002);
            }
            if(select.size() > 0 && (select.get(0).getStatus().equals(0) || select.get(0).getStatus().equals(1))){
                throw new OmcBizException(ErrorCodeEnum.OMC10036002);
            }
        }

        //查询房间交班项(周)
        List<OmcShifts> omcShiftsList = new ArrayList<>();
        if(omcRoomAssignment.getDate() != null && !omcRoomAssignment.getDate().equals("")){
            omcShiftsList = omcRoomAssignmentMapper.queryShiftsList(omcSchedulQuery);
        }
        //查询房间交班项(月)
        if(omcRoomAssignment.getMonth() != null && !omcRoomAssignment.getMonth().equals("")){
            omcShiftsList = omcRoomAssignmentMapper.queryShiftsListMonth(omcSchedulQuery);
        }
        List<Room> roomList = omcRoomAssignmentMapper.queryRoomList(nursingGroupId);
        List<OmcRoomAssignment> omcRoomAssignments = omcRoomAssignmentMapper.select(omcRoomAssignment);

        //最后需要的集合
        List<Room> resultRoomList = new ArrayList<Room>();
        for(int i=0;i<=roomList.size()-1;i++){
            //房间
            Room room = new Room();
            //班次集合
            List<OmcShifts> resultShiftList = new ArrayList<>();
            for(int j=0;j<=omcShiftsList.size()-1;j++){
                //班次——注意深浅拷贝的问题
                OmcShifts shift = new OmcShifts();
                BeanUtils.copyProperties(omcShiftsList.get(j),shift);

                //护工集合
                List<User> resultUserList = new ArrayList<User>();
                //当关系表中没有数据时，即没有给该组负责的所有房间安排护工时
                if(omcRoomAssignments == null || omcRoomAssignments.size() <= 0){
                    shift.setUserList(resultUserList);
                }else{
                    for(int k=0;k<=omcRoomAssignments.size()-1;k++){
                        //护工
                        User user = new User();
                        if (omcRoomAssignments.get(k).getRoomId().toString().equals(roomList.get(i).getRoomId().toString())
                            && omcRoomAssignments.get(k).getShiftsId().toString().equals(omcShiftsList.get(j).getId().toString())) {
                            user.setUserid(omcRoomAssignments.get(k).getUserId());
                            user.setRealname(omcRoomAssignments.get(k).getRealName());
                            resultUserList.add(user);
                        }
                    }
                    //设置班次的护工集合
                    shift.setUserList(resultUserList);
                }
                //添加班次
                resultShiftList.add(shift);
            }
            room = roomList.get(i);
            //设置房间的班次集合
            room.setOmcShiftsList(resultShiftList);
            //添加房间
            resultRoomList.add(room);
        }
        return resultRoomList;
    }

    @Override
    public List<OmcSchedul> queryScheduleAssList(OmcSchedul omcSchedul, String date, LoginAuthDto loginAuthDto) {

        //获取当前周是第几周
        Integer week = Integer.parseInt(date.substring(0, 4) + MenuTimeUtil.getDays(date).get(0));
//        System.out.println(date.substring(0, 4));
        omcSchedul.setWeek(week);

        //护工组护工集合
        List<OmcUserVo> userList = omcGroupService.selectByGroupId(omcSchedul.getNursingGroupId().longValue());

        //查询出该组负责的房间信息
        List<Room> roomList = omcGroupService.selectNursingBindRoom(omcSchedul.getNursingGroupId().longValue());

        OmcRoomAssignment roomAssignment = new OmcRoomAssignment();
        roomAssignment.setNursingGroupId(omcSchedul.getNursingGroupId());
        roomAssignment.setDate(date);

        //查询出关系表中的数据
        List<OmcRoomAssignment> roomAssList = select(roomAssignment);

        //查询的到该周的排班计划
        List<OmcSchedul> schedulList = omcScheduleService.queryShiftUsers(omcSchedul, loginAuthDto);

        /*  因为查询的是一周的排班计划，需求只需要一天的信息；排班计划中存放的是负责人id的字符串，
         * 需要先得到id的数组，然后与该组的负责人集合记性匹配得到负责人集合
         *   */
        //取得周一的每个班次的负责人
        if (omcSchedul.getMonDate() != null && omcSchedul.getMonDate().length() > 0) {
            for (int i = 0; i <= schedulList.size() - 1; i++) {
                String str = schedulList.get(i).getMonUserId();
                //获取负责人id集合
                if (!(str == null || str.length() <= 0)) {
                    //负责人id集合
                    List<Long> monUsers = NursinglogUtil.getUserList(str);
                    List<String> monRealNames = Lists.newArrayList();
                    if (StringUtils.isNotEmpty(schedulList.get(i).getMonRealName())) {
                        monRealNames = Arrays.asList(schedulList.get(i).getMonRealName().split("-"));
                    }
                    //负责人对象集合
                    List<User> users = new ArrayList<User>();
                    for (int a = 0; a <= monUsers.size() - 1; a++) {
                        if (monRealNames != null && monRealNames.size() == monUsers.size()) {
                            User user = new User();
                            user.setUserid(monUsers.get(a));
                            user.setRealname(monRealNames.get(a));
                            users.add(user);
                        } else {
                            for (int b = 0; b <= userList.size() - 1; b++) {
                                if (monUsers.get(a).equals(userList.get(b).getUserId())) {
                                    User user = new User();
                                    BeanUtils.copyProperties(userList.get(b), user);
                                    users.add(user);
                                    break;
                                }
                            }
                        }
                    }
                    for (int j = 0; j <= users.size() - 1; j++) {
                        //房间
                        List<Room> roomsList = new ArrayList<Room>();
                        for (int k = 0; k <= roomAssList.size() - 1; k++) {
                            for (int m = 0; m <= roomList.size() - 1; m++) {
                                if (roomAssList.get(k).getRoomId().equals(roomList.get(m).getRoomId()) &&
                                        roomAssList.get(k).getShiftsId().equals(schedulList.get(i).getShiftsId()) &&
                                        (long) roomAssList.get(k).getUserId() == users.get(j).getUserid()) {
                                    roomsList.add(roomList.get(m));
                                    break;
                                }
                            }
                        }
                        users.get(j).setRoomList(roomsList);
                    }
                    schedulList.get(i).getOmcShifts().setUserList(users);
                }
            }
        }
        //取得周二的每个班次的负责人
        if (omcSchedul.getTueDate() != null && omcSchedul.getTueDate().length() > 0) {
            for (int i = 0; i <= schedulList.size() - 1; i++) {
                String str = schedulList.get(i).getTueUserId();
                //获取负责人id集合
                if (!(str == null || str.length() <= 0)) {
                    List<Long> tueUsers = NursinglogUtil.getUserList(str);
                    List<String> tueRealNames = Lists.newArrayList();
                    if (StringUtils.isNotEmpty(schedulList.get(i).getTueRealName())) {
                        tueRealNames = Arrays.asList(schedulList.get(i).getTueRealName().split("-"));
                    }
                    List<User> users = new ArrayList<User>();
                    for (int a = 0; a <= tueUsers.size() - 1; a++) {
                        if (tueRealNames != null && tueRealNames.size() == tueUsers.size()) {
                            User user = new User();
                            user.setUserid(tueUsers.get(a));
                            user.setRealname(tueRealNames.get(a));
                            users.add(user);
                        } else {
                            for (int b = 0; b <= userList.size() - 1; b++) {
                                if (tueUsers.get(a).equals(userList.get(b).getUserId())) {
                                    User user = new User();
                                    BeanUtils.copyProperties(userList.get(b), user);
                                    users.add(user);
                                    break;
                                }
                            }
                        }
                    }
                    for (int j = 0; j <= users.size() - 1; j++) {
                        //房间
                        List<Room> roomsList = new ArrayList<Room>();
                        for (int k = 0; k <= roomAssList.size() - 1; k++) {
                            for (int m = 0; m <= roomList.size() - 1; m++) {
                                if (roomAssList.get(k).getRoomId().equals(roomList.get(m).getRoomId()) &&
                                        roomAssList.get(k).getShiftsId().equals(schedulList.get(i).getShiftsId()) &&
                                        (long) roomAssList.get(k).getUserId() == users.get(j).getUserid()) {
                                    roomsList.add(roomList.get(m));
                                    break;
                                }
                            }
                        }
                        users.get(j).setRoomList(roomsList);
                    }
                    schedulList.get(i).getOmcShifts().setUserList(users);
                }
            }
        }
        //取得周三的每个班次的负责人
        if (omcSchedul.getWedDate() != null && omcSchedul.getWedDate().length() > 0) {
            for (int i = 0; i <= schedulList.size() - 1; i++) {
                String str = schedulList.get(i).getWedUserId();
                //获取负责人id集合
                if (!(str == null || str.length() <= 0)) {
                    List<Long> wedUsers = NursinglogUtil.getUserList(str);
                    List<String> wedRealNames = Lists.newArrayList();
                    if (StringUtils.isNotEmpty(schedulList.get(i).getWedRealName())) {
                        wedRealNames = Arrays.asList(schedulList.get(i).getWedRealName().split("-"));
                    }
                    List<User> users = new ArrayList<User>();
                    for (int a = 0; a <= wedUsers.size() - 1; a++) {
                            if (wedRealNames != null && wedRealNames.size() == wedUsers.size()) {
                                User user = new User();
                                user.setUserid(wedUsers.get(a));
                                user.setRealname(wedRealNames.get(a));
                                users.add(user);
                            } else {
                                for (int b = 0; b <= userList.size() - 1; b++) {
                                if (wedUsers.get(a).equals(userList.get(b).getUserId())) {

                                    User user = new User();
                                    BeanUtils.copyProperties(userList.get(b), user);
                                    users.add(user);
                                    break;
                                }
                            }
                        }
                    }
                    for (int j = 0; j <= users.size() - 1; j++) {
                        //房间
                        List<Room> roomsList = new ArrayList<Room>();
                        for (int k = 0; k <= roomAssList.size() - 1; k++) {
                            for (int m = 0; m <= roomList.size() - 1; m++) {
                                if (roomAssList.get(k).getRoomId().equals(roomList.get(m).getRoomId()) &&
                                        roomAssList.get(k).getShiftsId().equals(schedulList.get(i).getShiftsId()) &&
                                        (long) roomAssList.get(k).getUserId() == users.get(j).getUserid()) {
                                    roomsList.add(roomList.get(m));
                                    break;
                                }
                            }
                        }
                        users.get(j).setRoomList(roomsList);
                    }
                    schedulList.get(i).getOmcShifts().setUserList(users);
                }

            }
        }
        //取得周四的每个班次的负责人
        if (omcSchedul.getThuDate() != null && omcSchedul.getThuDate().length() > 0) {
            for (int i = 0; i <= schedulList.size() - 1; i++) {
                String str = schedulList.get(i).getThuUserId();
                //获取负责人id集合
                if (!(str == null || str.length() <= 0)) {
                    List<Long> thuUsers = NursinglogUtil.getUserList(str);
                    List<String> thuRealNames = Lists.newArrayList();
                    if (StringUtils.isNotEmpty(schedulList.get(i).getThuRealName())) {
                        thuRealNames = Arrays.asList(schedulList.get(i).getThuRealName().split("-"));
                    }
                    List<User> users = new ArrayList<User>();
                    for (int a = 0; a <= thuUsers.size() - 1; a++) {

                            if (thuRealNames != null && thuRealNames.size() == thuUsers.size()) {
                                User user = new User();
                                user.setUserid(thuUsers.get(a));
                                user.setRealname(thuRealNames.get(a));
                                users.add(user);
                            } else {
                                for (int b = 0; b <= userList.size() - 1; b++) {
                                if (thuUsers.get(a).equals(userList.get(b).getUserId())) {
                                    User user = new User();
                                    BeanUtils.copyProperties(userList.get(b), user);
                                    users.add(user);
                                    break;
                                }
                            }
                        }
                    }
                    for (int j = 0; j <= users.size() - 1; j++) {
                        //房间
                        List<Room> roomsList = new ArrayList<Room>();
                        for (int k = 0; k <= roomAssList.size() - 1; k++) {
                            for (int m = 0; m <= roomList.size() - 1; m++) {
                                if (roomAssList.get(k).getRoomId().equals(roomList.get(m).getRoomId()) &&
                                        roomAssList.get(k).getShiftsId().equals(schedulList.get(i).getShiftsId()) &&
                                        (long) roomAssList.get(k).getUserId() == users.get(j).getUserid()) {
                                    roomsList.add(roomList.get(m));
                                    break;
                                }
                            }
                        }
                        users.get(j).setRoomList(roomsList);
                    }
                    schedulList.get(i).getOmcShifts().setUserList(users);
                }

            }
        }
        //取得周五的每个班次的负责人
        if (omcSchedul.getFriDate() != null && omcSchedul.getFriDate().length() > 0) {
            for (int i = 0; i <= schedulList.size() - 1; i++) {
                String str = schedulList.get(i).getFriUserId();
                //获取负责人id集合
                if (!(str == null || str.length() <= 0)) {
                    List<Long> friUsers = NursinglogUtil.getUserList(str);
                    List<String> friRealNames = Lists.newArrayList();
                    if (StringUtils.isNotEmpty(schedulList.get(i).getFriRealName())) {
                        friRealNames = Arrays.asList(schedulList.get(i).getFriRealName().split("-"));
                    }
                    List<User> users = new ArrayList<User>();
                    for (int a = 0; a <= friUsers.size() - 1; a++) {
                        if (friRealNames != null && friRealNames.size() == friUsers.size()) {
                            User user = new User();
                            user.setUserid(friUsers.get(a));
                            user.setRealname(friRealNames.get(a));
                            users.add(user);
                        } else {
                            for (int b = 0; b <= userList.size() - 1; b++) {
                                if (friUsers.get(a).equals(userList.get(b).getUserId())) {
                                    User user = new User();
                                    BeanUtils.copyProperties(userList.get(b), user);
                                    users.add(user);
                                    break;
                                }
                            }
                        }
                    }
                    for (int j = 0; j <= users.size() - 1; j++) {
                        //房间
                        List<Room> roomsList = new ArrayList<Room>();
                        for (int k = 0; k <= roomAssList.size() - 1; k++) {
                            for (int m = 0; m <= roomList.size() - 1; m++) {
                                if (roomAssList.get(k).getRoomId().equals(roomList.get(m).getRoomId()) &&
                                        roomAssList.get(k).getShiftsId().equals(schedulList.get(i).getShiftsId()) &&
                                        (long) roomAssList.get(k).getUserId() == users.get(j).getUserid()) {
                                    roomsList.add(roomList.get(m));
                                    break;
                                }
                            }
                        }
                        users.get(j).setRoomList(roomsList);
                    }
                    schedulList.get(i).getOmcShifts().setUserList(users);
                }
            }
        }
        //取得周六的每个班次的负责人
        if (omcSchedul.getSatDate() != null && omcSchedul.getSatDate().length() > 0) {
            for (int i = 0; i <= schedulList.size() - 1; i++) {
                String str = schedulList.get(i).getSatUserId();
                //获取负责人id集合
                if (!(str == null || str.length() <= 0)) {
                    List<Long> satUsers = NursinglogUtil.getUserList(str);
                    List<String> satRealNames = Lists.newArrayList();
                    if (StringUtils.isNotEmpty(schedulList.get(i).getSatRealName())) {
                        satRealNames = Arrays.asList(schedulList.get(i).getSatRealName().split("-"));
                    }
                    List<User> users = new ArrayList<User>();
                    for (int a = 0; a <= satUsers.size() - 1; a++) {
                        if (satRealNames != null && satRealNames.size() == satUsers.size()) {
                            User user = new User();
                            user.setUserid(satUsers.get(a));
                            user.setRealname(satRealNames.get(a));
                            users.add(user);
                        } else {
                            for (int b = 0; b <= userList.size() - 1; b++) {
                                if (satUsers.get(a).equals(userList.get(b).getUserId())) {
                                    User user = new User();
                                    BeanUtils.copyProperties(userList.get(b), user);
                                    users.add(user);
                                    break;
                                }
                            }
                        }
                    }
                    for (int j = 0; j <= users.size() - 1; j++) {
                        //房间
                        List<Room> roomsList = new ArrayList<Room>();
                        for (int k = 0; k <= roomAssList.size() - 1; k++) {
                            for (int m = 0; m <= roomList.size() - 1; m++) {
                                if (roomAssList.get(k).getRoomId().equals(roomList.get(m).getRoomId()) &&
                                        roomAssList.get(k).getShiftsId().equals(schedulList.get(i).getShiftsId()) &&
                                        (long) roomAssList.get(k).getUserId() == users.get(j).getUserid()) {
                                    roomsList.add(roomList.get(m));
                                    break;
                                }
                            }
                        }
                        users.get(j).setRoomList(roomsList);
                    }
                    schedulList.get(i).getOmcShifts().setUserList(users);
                }
            }
        }
        //取得周日的每个班次的负责人
        if (omcSchedul.getSunDate() != null && omcSchedul.getSunDate().length() > 0) {
            for (int i = 0; i <= schedulList.size() - 1; i++) {
                String str = schedulList.get(i).getSunUserId();
                //获取负责人id集合
                if (!(str == null || str.length() <= 0)) {
                    List<Long> sunUsers = NursinglogUtil.getUserList(str);
                    List<String> sunRealNames = Lists.newArrayList();
                    if (StringUtils.isNotEmpty(schedulList.get(i).getSunRealName())) {
                        sunRealNames = Arrays.asList(schedulList.get(i).getSunRealName().split("-"));
                    }
                    List<User> users = new ArrayList<User>();
                    for (int a = 0; a <= sunUsers.size() - 1; a++) {
                        if (sunRealNames != null && sunRealNames.size() == sunUsers.size()) {
                            User user = new User();
                            user.setUserid(sunUsers.get(a));
                            user.setRealname(sunRealNames.get(a));
                            users.add(user);
                        } else {
                            for (int b = 0; b <= userList.size() - 1; b++) {
                                if (sunUsers.get(a).equals(userList.get(b).getUserId())) {
                                    User user = new User();
                                    BeanUtils.copyProperties(userList.get(b), user);
                                    users.add(user);
                                    break;
                                }
                            }
                        }
                    }
                    for (int j = 0; j <= users.size() - 1; j++) {
                        //房间
                        List<Room> roomsList = new ArrayList<Room>();
                        for (int k = 0; k <= roomAssList.size() - 1; k++) {
                            for (int m = 0; m <= roomList.size() - 1; m++) {
                                if (roomAssList.get(k).getRoomId().equals(roomList.get(m).getRoomId()) &&
                                        roomAssList.get(k).getShiftsId().equals(schedulList.get(i).getShiftsId()) &&
                                        (long) roomAssList.get(k).getUserId() == users.get(j).getUserid()) {
                                    roomsList.add(roomList.get(m));
                                    break;
                                }
                            }
                        }
                        users.get(j).setRoomList(roomsList);
                    }
                    schedulList.get(i).getOmcShifts().setUserList(users);
                }
            }
        }
        return schedulList;
    }

    @Override
    public List<OmcShifts> queryShiftsList(OmcSchedul omcSchedulQuery) {
        //查询房间交班项
        List<OmcShifts> omcShiftsList = omcRoomAssignmentMapper.queryShiftsList(omcSchedulQuery);
        return omcShiftsList;
    }

    /**
     * 月排班签到
     * @return null
     * @author HD
     * @date  20:06
     */
    @Override
    public RoomAndNursingVo queryScheduleMonth(OmcSchedul omcSchedul, String date, LoginAuthDto loginAuthDto) {
        //护工组护工集合
        List<OmcUserVo> userList = omcGroupService.selectByGroupId(omcSchedul.getNursingGroupId().longValue());

        //查询出该组负责的房间信息
        List<Room> roomList = omcGroupService.selectNursingBindRoom(omcSchedul.getNursingGroupId().longValue());

        OmcRoomAssignment roomAssignment = new OmcRoomAssignment();
        roomAssignment.setNursingGroupId(omcSchedul.getNursingGroupId());
        roomAssignment.setDate(date);

        //查询出关系表中的数据
        List<OmcRoomAssignment> roomAssList = select(roomAssignment);
        RoomAndNursingVo roomAndNursingVo = new RoomAndNursingVo();
        roomAndNursingVo.setRoomList(roomList);
        roomAndNursingVo.setUserList(userList);
        roomAndNursingVo.setRoomAssList(roomAssList);
        return roomAndNursingVo;
    }

    public int getNursingGroupId(Integer omcNurisngGroupId,LoginAuthDto loginAuthDto){

        //查询用户身份
        List<RpcRoleVo> rpcRoleVos = uacRpcService.queryRoleListByUserId(loginAuthDto.getUserId());

        //定义班组id
        Integer nursingGroupId = 0;

        for(RpcRoleVo vo : rpcRoleVos){
            //1.身份为护工时，班组id为护工所在的班组id
            if(vo.getRoleCode().equals("nursing")){
                nursingGroupId = omcGroupService.selectNuringGroupIdByUserId(loginAuthDto.getUserId()).intValue();
                //2.身份为服务部长时，班组id为服务部长指定的id
            }else {
                nursingGroupId = omcNurisngGroupId;
            }
        }
        if( nursingGroupId == null || nursingGroupId == 0 ){
            throw new OmcBizException(ErrorCodeEnum.OMC10035006);
        }

        return nursingGroupId;
    }
}
